package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.ServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

@Validated
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务相关接口")
public class ServeController {

    @Resource
    private ServeService serveService;

    @GetMapping(path = "/page")
    @ApiOperation("区域服务分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO) {
        return serveService.page(servePageQueryReqDTO);
    }

    @PostMapping(path = "/batch")
    @ApiOperation("区域服务批量新增")
    public void add(@RequestBody List<ServeUpsertReqDTO> list){
        serveService.add(list);
    }

    @PutMapping(path = "/{id}")
    @ApiOperation("修改价格")
    public void updatePrice(@PathVariable("id") Long id, @RequestParam("price") BigDecimal price) {
        serveService.updatePrice(id, price);
    }

    @PutMapping(path = "/onSale/{id}")
    @ApiOperation("上架服务")
    public void onSale(@PathVariable("id") Long id) {
        serveService.onSale(id);
    }

    @DeleteMapping(path = "/{id}")
    @ApiOperation("删除服务")
    public void delete(@PathVariable("id") Long id) {
        serveService.deleteById(id);
    }

    @PutMapping(path = "/offSale/{id}")
    @ApiOperation("下架服务")
    public void offSale(@PathVariable("id") Long id) {
        serveService.offSale(id);
    }

    @PutMapping(path = "/onHot/{id}")
    @ApiOperation("设置热门开发")
    public void onHot(@PathVariable("id") Long id) {
        serveService.onHot(id);
    }

    @PutMapping(path = "/offHot/{id}")
    @ApiOperation("取消热门")
    public void offHot(@PathVariable("id") Long id) {
        serveService.offHot(id);
    }
}
